from django.db.models.signals import pre_save
from django.dispatch import receiver
from .models import Type, Video

@receiver(pre_save, sender=Type)
def update_video_type_nameid(sender, instance, **kwargs):
    if instance.pk:
        try:
            old_instance = Type.objects.get(pk=instance.pk)
            if old_instance.nameid != instance.nameid:
                Video.objects.filter(type_nameid=old_instance.nameid).update(type_nameid=instance.nameid)
        except Type.DoesNotExist:
            pass
